class PLAYER : public STATS {
    public:
        PLAYER();
        ~PLAYER();
        
        //properties
        short id;
        int lives;
        bool quit;
        bool touchingGround;
        bool toggle;
        
        //behaviors
        int Update();
        
    private:
        bool rushBought;
};

int PLAYER::Update()
{
    oslDrawImage(image);
    
    //gravity
    if(image->y != (GROUND - image->stretchY)){touchingGround = 0; sy++;}
    if(image->y > (GROUND - image->stretchY)){image->y = (GROUND - image->stretchY); sy = 0;}
    else if(image->y == (GROUND - image->stretchY)) touchingGround = 1;
    image->y+=sy;
    
    //handle player health and lives
    if(health <= 0){
        lives--; image->y = 20; 
        image->x = 240; 
        health = 100;
    }
    if(lives < 0) quit = true;
    
    /* keep within the screen */
    if(image->x > (480 - image->stretchX))
      {oslPlaySound(block, 2); image->x = (479 - image->stretchX);}
    if(image->x <= 0)
      {oslPlaySound(block, 7); image->x = 1;}
    

    oslReadKeys();
    
    //pausing
    if(osl_keys->pressed.start)PauseGame(quit);
    
    //toggle onscreen text
    if(osl_keys->pressed.select) {if(toggle)toggle = false; else toggle = true;}
    
    //jumping
    if(osl_keys->pressed.cross && touchingGround) {
        sy -= jumpHeight;
        oslPlaySound(jump, 3);
    }
    
    //rushing
    if(osl_keys->held.R && rushBought && facing != STILL) {
        oslPlaySound(rush, 4);
        if(facing == FACING_LEFT) image->x -= 10;
        if(facing == FACING_RIGHT)image->x += 10;
    }
    
    //attacking
    if(osl_keys->pressed.square)
    {    
        if(facing == FACING_RIGHT) {
            position = ATTACKING_RIGHT;
            create.ShootNextBullet(1, image->x, image->y);
        }
        if(facing == FACING_LEFT)  {
            position = ATTACKING_LEFT;
            create.ShootNextBullet(0, image->x, image->y);
        }
        
        SpriteAnimate();
    }
    
    //moving left
    if(osl_keys->held.left){
        position = LEFT; 
        facing = FACING_LEFT; 
        image->x-=3;
        SpriteAnimate();
    }
    
    //moving right
    else if(osl_keys->held.right)
    { 
        position = RIGHT; 
        facing = FACING_RIGHT; 
        image->x+=3; 
        SpriteAnimate();
    }
    
    //press downwards
    else if(osl_keys->pressed.down)
    {
        position = NOT_MOVING;
        facing = STILL;
        SpriteAnimate();
    }
    
    return 0;
}

PLAYER::PLAYER()
{
    health = 100;
    lives = 3;
    quit = false;
    position = NOT_MOVING;
    facing = STILL;
    rushBought = true;
    equippedWeapon = DEFAULT_0;
    
    return;
}

PLAYER::~PLAYER()
{
    return;
}
